from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from time import sleep


import sys

sys.path.append(r'..')
from web_base.base_page import BasePage
from page_object.login_page import LoginPage

class PersonalPage(BasePage):
    url = r'/bsams/front/asset_user/user_info.do'

    #修改密码定位
    mod_ben_loc = (By.XPATH, '/html/body/div[1]/div/div[1]/a')
    mod_oldPassword_loc = (By.ID, 'oldPassword')
    mod_newPassword1_loc = (By.ID, 'newPassword1')
    mod_newPassword2_loc = (By.ID, 'newPassword2')
    mod_ok_loc = (By.CLASS_NAME, 'button_fujian.margin')
    
    # 手机号定位
    add_ben_loc = (By.XPATH, '//*[@id="leftmenu_asset_user"]/div[1]/a/img')
    mod_phone_loc = (By.ID, 'phone')
    mod_ok_loc = (By.CLASS_NAME, 'button_fujian')

    # 退出定位
    logout_ben_loc = (By.CLASS_NAME, 'exit.right')
    
    def change_password(self,pwd,newpwd,newspwd):
        self.open()
        self.ele_click(self.mod_ben_loc)
        sleep(2)
        self.ele_input(self.mod_oldPassword_loc,pwd)
        sleep(2)
        self.ele_input(self.mod_newPassword1_loc,newpwd)
        sleep(2)
        self.ele_input(self.mod_newPassword2_loc, newspwd)
        sleep(1)
        self.ele_click(self.mod_ok_loc)
        sleep(3)

    def change_phone(self, phone):
        self.open()
        self.ele_click(self.add_ben_loc)
        sleep(2)
        self.ele_clear(self.mod_phone_loc)
        self.ele_input(self.mod_phone_loc, phone)
        sleep(1)
        self.ele_click(self.mod_ok_loc)
        sleep(3)
    
    def logout(self):
        self.open()
        sleep(2)
        self.ele_click(self.logout_ben_loc)

